package com.ysd.lis.service.impl;

import com.ysd.common.Result;
import com.ysd.lis.entity.SysUserDept;
import com.ysd.lis.mapper.sys.SysUserDeptMapper;
import com.ysd.lis.service.SysUserDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * cold_chain.t_user_dept 服务实现类
 * </p>
 *
 * @author Peng
 * @since 2021-10-08
 */
@Service
public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptMapper, SysUserDept> implements SysUserDeptService {
    @Autowired
    SysUserDeptMapper sysUserDeptMapper;

    @Override
    public Result findUserDepts(String userId) {
        List<Map<String,Object>> list =  sysUserDeptMapper.findUserDepts(userId);
        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> returnList = new ArrayList<>();

        for(Map<String,Object> m :list){
            Map<String,Object> returnMap = new HashMap<>();
            returnMap.put("userId",m.get("userId"));
            returnMap.put("deptId",m.get("deptId"));
            Map<String,Object> deptMap = new HashMap<>();
            deptMap.put("id",m.get("deptId"));
            deptMap.put("name",m.get("deptName"));
            deptMap.put("code",m.get("deptCode"));
            returnMap.put("Department",deptMap);
            returnList.add(returnMap);
        }
        map.put("userDepts",returnList);
        return  Result.succ(1,"查询成功",map);
    }
}
